home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8177 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.6 KB

  1. Path: anvil.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: F-keys/cursor keys w/curses?
  5. Followup-To: comp.unix.programmer
  6. Date: 1 Mar 1996 12:33:56 -0800
  7. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  8. Message-ID: <4h7mvkINNstb@anvil.ugrad.cs.ubc.ca>
  9. References: <schellerDnHwLr.FJ9@netcom.com> <96061.093728U14873@uicvm.uic.edu>
  10. NNTP-Posting-Host: anvil.ugrad.cs.ubc.ca
  11.  
  12. In article <96061.093728U14873@uicvm.uic.edu>,
  13. Bob Hyman  <U14873@uicvm.uic.edu> wrote:
  14. >>scheller@netcom.com (Mark J. Scheller) says:
  15. >>  ... using curses ...  One thing I would like to do is take action
  16. >>based on the user pressing a cursor key or a function key.  I'm using
  17. >>getch() to grab the keypresses -- the problem is that the cursor
  18. >>keys and the function keys return multiple key sequences for a keypress.
  19. >>Is there something better to use?
  20. >>  ...
  21. >
  22. >A member of my group just got ncurses.  It has support for converting
  23. >a sequence of input characters into a keypress.  I haven't tried it
  24. >yet, though.
  25.  
  26. So does SVR4 curses, which ncurses is strongly modelled on. Curses can detect
  27. things like function keys and arrow keys, and turn them into keycodes that are
  28. defines a symbolic constants:
  29.  
  30. From the curses manual page:
  31.  
  32.       The following function keys could possibly be returned by getch if
  33.       keypad has been enabled.  Note that not all of these are currently
  34.       supported due to lack of definitions in terminfo or the terminal not
  35.       transmitting a unique code when the key is pressed.
  36.  
  37.       Name           Value                    Key name
  38.       KEY_BREAK      0401                     break key (unreliable)
  39.       KEY_DOWN       0402                     The four arrow keys ...
  40.       KEY_UP         0403
  41.       KEY_LEFT       0404
  42.       KEY_RIGHT      0405
  43.       KEY_HOME       0406                     Home key (upward+left arrow)
  44.       KEY_BACKSPACE  0407                     backspace (unreliable)
  45.       KEY_F0         0410                     Function keys.  Space reserved
  46.  
  47.  
  48. *If* the keypad has been enabled. As I already pointed out to the poster, he
  49. should execute
  50.  
  51.     keypad(stdscr, TRUE);
  52.  
  53. in his curses initialization code.
  54.  
  55. Also, many curses implementations have a bug. When you use endwin() before
  56. ``shelling out'' to a shell prompt (needed by interactive programs with shell
  57. escapes, or ones which launch scripts), when you come back, the arrow keys may
  58. not work properly.
  59.  
  60. The solution is to call keypad(stdscr, TRUE) again when you restore curses, in
  61. additional to the recommended procedure.
  62.  
  63. (redirected to comp.unix.programmer)
  64. -- 
  65.  
  66.